/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.matrimony.db;

import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author yoko
 */
public class MyConnection {
    
 public static Connection openConnection(){
      Connection cnn=null;
      String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
      String connectionUrl = "jdbc:sqlserver://localhost;databaseName=Matrimony";
      try {
         Class.forName(driver);
         cnn=DriverManager.getConnection(connectionUrl,"sa","123456");
     } catch (Exception e) {
         Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE,null, e);
     }
      return cnn;
 }

 public static void closeConnection(Connection cnn, PreparedStatement stm, ResultSet rs){
        try {
         if(rs!=null){
             rs.close();
         }
         if(stm!=null){
             stm.close();
         }
         if(cnn!=null){
             cnn.commit();
             cnn.close();
         }
     } catch (Exception e) {
         Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE,null, e);
     }
 }
 
  
 public static Connection connType4() {
        Connection cnn = null;
     
        try {

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            cnn = DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=Matrimony","sa", "123456");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

        return cnn;

    }
 
 public static void main(String[] args){
     System.out.println(openConnection().toString());
 }
}
